home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: MegaDisc
/
MegaDisc 08 (1988)(MegaDisc Digital Publishing)(AU)[WB].zip
/
MegaDisc 08 (1988)(MegaDisc Digital Publishing)(AU)[WB].adf
/
TUTORIALS
/
BASIC
/
Basic_Tute
< prev
next >
Wrap
Text File
|
1988-05-28
|
17KB
|
438 lines
AMIGABASIC TUTORIAL PARTS 4-6
By Jonathan Potter.
DRAWING FUNCTIONS
All of the AmigaBASIC drawing functions take the
form (x,y) or (x1,y1)-(x2,y2).
A brief run down of them follows.
CIRCLE [STEP] (x,y),radius [,colour id [,start,end[,aspect]]]
(x,y) are the coordinates for the origin of the circle.
<radius> is the radius in pixels.
<colour id> is the drawing colour
<start> and <end> refer to the start and end angles in radians,
and range from -2pi to 2pi. These angles allow the user to specify where
an ellipse starts and ends. If <start> or <end> are negative, the circle
is connected to the origin with a line, and the angles treated as
positives. <aspect> is the ratio of the width to height of one pixel
(eg, the aspect ratio of an 1081 monitor is 2.25:1, so the <aspect> would
be 1/2.25, which is .44. This is the default). The [STEP] option is
present in most drawing commands, and indicates that the x and y
coordinates are relative to the current, or last referenced coordinates
of the pen. (e.g if the last referenced point was (10,10), the command
CIRCLE STEP (20,15),10 would draw a circle with origin (30,25) and radius
10).
EXAMPLES
CIRCLE (100,100),100
- circle with radius 100, origin (100,100)
CIRCLE (300,30),50,4,,,.5
- circle with radius 50, origin (300,30), colour 4, with
aspect ratio of .5 (i.e pixels twice high as wide.)
CIRCLE (300,100),100,,1.5,4.5
- circle with radius 100, origin (300,100), starting at 1.5
rads, and ending at 4.5 rads.
LINE [[STEP](x1,y1)-[STEP](x2,y2),[colour-id] [,b[f]]
(x1,y1) are the starting coordinates for the line. As in circle,
STEP indicates to refer to the pen position.
(x2,y2) are the ending coordinates for the line. This time, STEP
refers to the (x1,y1) coordinates.
<colour-id> is the drawing colour. The b paramater makes a box
be drawn instead of a line. In this case, (x1,y1) are the upper-left
coordinates, and (x2,y2) the lower-right.
The bf paramater causes the box to be filled in.
EXAMPLES
LINE (10,10)-(100,100),3
- draws a line from (10,10) to (100, 100) in colour 3
LINE (100,100)-(150,120),,bf
- draws a filled in box with upper-left coordinates (100,100)
and lower right coordinates (150,120)
LINE STEP (10,10)- STEP (30,50),,b
- draws a box with upper-left coordinates (10,10) from last
referenced position, and lower- right coordinates (30,50)
from (10,10) the first coordinates.
PAINT [STEP](x,y)[,paintColour-id
[,borderColour-id]]
(x,y) are the coordinates of any point within the area to be
painted (filled) STEP again refers to a relative point.
<paintColour-id> is the colour that the area is to be painted.
<borderColour-id> is the colour of the border surrounding the
to-be-painted area (i.e the colour at which filling stops.) If this value
is not specified, <paintColour-id> is used.
EXAMPLES
PAINT (100,100),5,3
- fills in an area with an interior point (100,100), with
colour 5, stopping at colour 3.
PAINT (50,300),2
- fills an area with interior point (50,300) with colour 2,
not stopping until colour 2 is found.
BASIC TUTORIAL PART 5
PALETTE <colour-id>,<redvalue>,<greenvalue>,<bluevalue>
PALETTE allows you to set the colour registers for your programme.
<colour-id> is the colour register, a value from 0 to 31. (0 is
the background colour).
<redvalue>
<greenvalue>
<bluevalue> are values from 0.00 to 1.00, indicating a decimal
percentage of red, green and blue. Combined these paramaters define a
colour.
EXAMPLES
PALETTE 0,1,1,1 - sets the background colour to white.
PALETTE 1,1,.6,0 - sets register 1 to orange.
PALETTE 18,.8,0,.93 - sets register 18 to purple.
POINT (x,y)
POINT returns the colour id of the point at (x,y)
EXAMPLES
PRINT POINT (100,100) - prints the colour id at the point
(100,100)
IF POINT(300,10)=0 THEN main - goes to main: if the
point at (300,10) is blank (0 is the default background
colour)
PSET [STEP] (x,y) [,<colour id>]
PSET sets a point (x,y) in the current output window to
the current foreground colour (default is colour id 1)
if none is specified, otherwise to the colour specified
by <colour id>. As with other commands, STEP specifies
a location relative to the last referenced point, rather
than an absolute point.
EXAMPLES
PSET (100,100),3 - sets point at (100,100) to colour 3.
PSET STEP (300,-10) - sets point 300 pixels to the left,
and ten pixels up from the last referenced point to
the current foreground colour.
PRESET [STEP] (x,y) [,<colour id>]
PRESET is identical to PSET in every way except one -
if <colour id> is omitted the point is set to
the current background colour, rather than the foreground.
EXAMPLES
PRESET (100,100),3 - does exactly the same thing as
the first example for PSET.
PRESET STEP (300,-10) - sets point 300 pixels to the
left, and ten pixels up from the last referenced
point (as did the second example for PSET) but in
the background colour rather than the foreground colour.
AREA [STEP] (x,y)
AREA defines a point of a polygon to be acted upon
by AREAFILL. The (x,y) parameters specify one of up
to twenty points that form a polygon. If STEP is
specified, (x,y) are relative from the last AREA (x,y)
parameters.
AREA is reset after AREAFILL has been executed, so if
you wish to AREAFILL the same polygon again, you
must redefine it with AREA.
EXAMPLES
AREA (10,10):AREA (100,10):AREA (100,50): AREA(10,50) -
defines a square with corners at (10,10), (100,10),
(100,50) and (10,50).
AREA (100,10):AREA STEP (50,0):AREA STEP (0,50):
AREA STEP (-50,0) - defines a square with sides of 50
(its corners are at (100,10), (150,10), (150,60) and
(100,60).)
AREAFILL [mode]
AREAFILL alters the interior of the polygon defined by
AREA statements.
The [mode] parameter is either 0 or 1.
0 - fills the area with the area pattern established
by a PATTERN command.
1 - inverts (reverses colours in the) the area.
0 is the default parameter - if no [mode] is specified,
the pattern defined by PATTERN will be used.
EXAMPLES
AREAFILL 1 - will invert (reverse) the colours in a
defined area. This, for example, generates the same
effect as clicking with the left mouse button and
holding on a Boolean type gadget (e.g the CANCEL of a
system request). Here is an example of a gadget in
AmigaBASIC, to demonstrate one of the uses of AREAFILL 1.
gadget:
'AmigaBasic gadget (C) 1988 Jonathan Potter
LINE (10,10)-(70,40),1,b:LINE (12,12)-(68,38),3,b
LOCATE 3,3:PRINT"CLICK!"
waitforclick:
IF MOUSE(0)=0 THEN waitforclick
m1=MOUSE(1):m2=MOUSE(2)
IF m1<10 OR m1>70 OR m2<10 OR m2>40 THEN
WHILE MOUSE(0)<>0:SLEEP:WEND
GOTO waitforclick
END IF
AREA (10,10):AREA (70,10):AREA (70,40):AREA (10,40)
AREAFILL 1:out=0
WHILE MOUSE(0)<>0
m1=mouse(1):m2=mouse(2)
IF out=0 THEN IF m1<10 or m1>70 or m2<10 or m2>40 THEN
AREA(10,10):AREA (70,10):AREA (70,40):AREA (10,40)
out=1: AREAFILL 1
END IF
IF out=1 THEN IF m1>9 and m1<71 and m2>9 and m2<41 THEN
AREA(10,10):AREA (70,10):AREA (70,40):AREA (10,40)
out=0:AREAFILL 1
END IF
WEND
IF out=0 THEN
AREA(10,10):AREA (70,10):AREA (70,40):AREA (10,40):AREAFILL 1
LOCATE 10,1:PRINT"You Clicked!":END
END IF
IF out=1 THEN out=0:GOTO waitforclick
If that routine uses commands you are unfamiliar with,
don't worry. It is likely they will be covered in later
tutorials. That routine was just to demonstrate one of
the uses of AREAFILL 1.
AREAFILL 0 - this will fill in the defined area with
the pattern specified by PATTERN.
PATTERN [<line pattern>][,<area pattern>]
PATTERN allows textured fills of polygons, and
lines and text.
<line pattern> is a hexadecimal number that defines a 16 bit
value to be used for line drawing.
<area pattern> is the name of an integer array containing
the pattern. The array defines a 16 bit wide by 2^n high
value to be used for AREAFILL 0 where n is any integer from
1 to 5 inclusive. The array contains 2^n elements.
Determining the 16 bit and 16X2^n bit values is somewhat
reminiscent of designing sprites on the C64.
Each 16 bit long line (only one in the <line pattern>) consists
of on and off pixels. e.g for a dotted line effect the
binary value would be 1010101010101010. This must then be
converted to a hex value which in this case is &HAAAA (each of
the four groups of four bits (1010) yields in this case a decimal
10, which is A in hex.)
If the command PATTERN &HAAAA was executed, subsequent lines and
text drawn would be dotted (on/off/on/off....). This would
continue until a solid <line pattern> was defined (1111111111111111)
which is hex &HFFFF. (e.g PATTERN &HFFFF)
If you defined an array, say for example pat%, like this:
DIM pat%(1)
pat%(0)=&HAAAA (&HAAAA is 1010101010101010)
pat%(1)=&H5555 (&H5555 is 0101010101010101)
and then executed the command
PATTERN ,pat%
any subsequent AREAFILL 0 commands would fill the area with
the pattern defined in array pat%, in this case, a dotted
pattern. This would continue until
DIM pat%(1)
pat%(0)=&HFFFF
pat%(1)=&HFFFF
PATTERN ,pat%
was executed, resetting the fill pattern to solid.
BASIC TUTORIAL PART 6
GET (<x1>,<y1>)-(<x2>,<y2>),<array-name>[(index list]
GET has two functions - a graphical function
(described below), and an I/O function (which will
be described in later tutorials).
GET is used in conjunction with PUT (see below) to
transferring graphic images from one part of the screen
to another.
(<x1>,<y1>) and (<x2>,<y2>) are the top left and bottom
right corners respectively of the rectangle you wish to
GET.
<array-name> is the name of the array that will hold
the image. The array can be any type except a string,
but the contents of the array will be meaningless when
directly interpreted, unless the array is an integer
(e.g array%). The array must
The required dimension of the array is calculated by
the following formula :
(6+((y+1)*2*INT((x+16)/16)*D)/BYTES
where x and y are the lengths of the horizontal and
vertical sides of the rectangle (x and y can be
calculated like so: x=x2-x1 and y=y2-y1), and D is
the screen depth (see AMIGABASIC TUTORIAL PART 1 for a
discussion on depth) for which 2 is the default.
BYTES is the number of bytes per element of an array,
which are:
integer - 2 bytes
single precision - 4 bytes
double precision - 8 bytes
Therefore, if you wished to
GET (10,20)-(30,40),ARRAY%
from the normal Workbench screen (depth of 2), the number
of elements required for ARRAY% is
(6+((20+1)*2*(INT((20)+16)/16))*2)/2
which works out to be 87 elements.
Therefore, you would have to DIM ARRAY%(87)
The <index-list> allows you to define multiple images
in a multidimensional array.
PUT [STEP] (<x>,<y>), <array-name> [(index-list)]
[action-verb]
PUT, like GET, has a graphical and an I/O function.
The I/O function will be discussed in future tutorials.
PUT is used to place an image defined by GET from the
array <array-name> on the screen, with top left
coordinates (<x>,<y>). The <index-list> allows mutiple
images in a multidimensional array. STEP again refers
to a point relative from the last referenced point,
rather than an absolute point.
<action-verb> is one of PSET, PRESET, AND, OR or XOR,
and defines how the placement will interact with
the screen.
PSET will place the image on the screen, totally
obscuring anything underneath it.
PRESET will do the same as PSET, but will invert
(reverse) the colours.
AND will perform a logical And on the image and what
is already on the screen, and display the result.
OR will perform a logical Or on the image and what is
already on the screen, and display the result.
XOR (which is the default) will place the image over
the top of whatever is already on the screen, but will
let what is there show through.
EXAMPLES
PUT (20,90),ARRAY%,PSET - places the image from ARRAY% on
the screen at (20,90) obscuring what is already there.
PUT STEP (10,10),ARRAY% - places the image from ARRAY% on
the screen (10,10) from the last referenced point.
COLOR [<foreground colour id>] [,<background colour id>]
COLOR allows you to set the current foreground and
background drawing colours.
<foreground colour id> is a value from 0 to 31, which
corresponds to a colour register set by the PALETTE
command.
<background colour id> is a value from 0 to 31, which
corresponds to a colour register set by the PALETTE
command.
All graphics and text will be drawn in the current
foreground colour, unless specified otherwise.
EXAMPLES
COLOR 1,0 - this is the default colour setup, which,
with the default system colours, produces white text
on a blue background.
COLOR 0,1 - with the default system colours, this
produces blue text on a white background.
COLOR 3,2 - foreground colour 3, background colour 2
COLOR 8 - foreground colour 8, background colour
unchanged.
COLOR ,9 - foreground colour unchanged, background
colour 9.
WINDOW CLOSE <window-id>
WINDOW OUTPUT <window-id>
SCREEN CLOSE <screen-id>
WINDOW <n>
These four commands were inadvertantly left out of
previous tutorials. Briefly,
WINDOW CLOSE will close a window once it has been opened.
<window-id> is the id of the window.
WINDOW OUTPUT will direct all screen output (text, graphics,
etc.) to the window <window-id>. Default for this
is 1 (the default AmigaBASIC output window).
SCREEN CLOSE will close a screen once it has been opened.
<screen-id> is the id of the screen.
WINDOW <n> will return information about the status
and size of the current output window. <n> is any number
from 0 to 8.
<n> value Information returned
0 The window-id of the selected output window.
1 The window-id of the current output window.
2 The width of the current output window.
3 The height of the current output window.
4 The x coordinate in the current output window
where the next character is drawn.
5 The y coordinate in the current output window
where the next character is drawn.
6 The maximum legal colour for the current output
window.
7 A pointer to the INTUITION WINDOW record for the
current output window.
8 A pointer to the RASTPORT record for the current
output window.
These last two are not necessary for the casual programmer,
however, if you require information about them, see the manual
"Intuition: The Amiga User Interface"
EXAMPLES
WINDOW CLOSE 1 - will close window 1 (when AmigaBASIC is
first started this is the output window)
WINDOW OUTPUT 3 - will direct screen output to window 3.
SCREEN CLOSE 2 - will close screen 2.
PRINT WINDOW(2)*WINDOW(3) - will return the area in pixels of
the current output window (useful!)
XXXXXXXXXXXXXXXXXXXXXXXXXXX END OF BASIC_TUTE XXXXXXXXXXXXXXXXXXXXXXXXXXXX